
cd "$Mydirectory1/1_DataSources/NLSY79/"

//read in data file
	clear all
	set maxvar 10000
	insheet using ./rawdata/employment_status_byintdate.csv, clear comma

//for some reason, var names are uncapitalized when brought in. Need to be capitalized so that nls-provided cleanup will work
	ren r* R*
	ren t* T*
	
* do nls-provided cleanup *
label define vlR0173600 1 "CROSS MALE WHITE"  2 "CROSS MALE WH. POOR"  3 "CROSS MALE BLACK"  4 "CROSS MALE HISPANIC"  5 "CROSS FEMALE WHITE"  6 "CROSS FEMALE WH POOR"  7 "CROSS FEMALE BLACK"  8 "CROSS FEMALE HISPANIC"  9 "SUP MALE WH POOR"  10 "SUP MALE BLACK"  11 "SUP MALE HISPANIC"  12 "SUP FEM WH POOR"  13 "SUP FEMALE BLACK"  14 "SUP FEMALE HISPANIC"  15 "MIL MALE WHITE"  16 "MIL MALE BLACK"  17 "MIL MALE HISPANIC"  18 "MIL FEMALE WHITE"  19 "MIL FEMALE BLACK"  20 "MIL FEMALE HISPANIC" 
label values R0173600 vlR0173600

label define vlR0214700 1 "HISPANIC"  2 "BLACK"  3 "NON-BLACK, NON-HISPANIC" 
label values R0214700 vlR0214700

label define vlR0214800 1 "MALE"  2 "FEMALE" 
label values R0214800 vlR0214800

label define vlR0406511 1 "1: 1  YES"  0 "0: 0  NO" 
label values R0406511 vlR0406511

label define vlR0645680 1 "1: 1  YES"  0 "0: 0  NO" 
label values R0645680 vlR0645680

label define vlR0896711 1 "1: 1  YES"  0 "0: 0  NO" 
label values R0896711 vlR0896711

label define vlR1145111 1 "1: 1  YES"  0 "0: 0  NO" 
label values R1145111 vlR1145111

label define vlR1520311 1 "1: 1  YES"  0 "0: 0  NO" 
label values R1520311 vlR1520311

label define vlR1891011 1 "1: 1  YES"  0 "0: 0  NO" 
label values R1891011 vlR1891011

label define vlR2258111 1 "1: 1  YES"  0 "0: 0  NO" 
label values R2258111 vlR2258111

label define vlR2445511 1 "1: 1  YES"  0 "0: 0  NO" 
label values R2445511 vlR2445511

label define vlR2871301 1 "1: 1  YES"  0 "0: 0  NO" 
label values R2871301 vlR2871301

label define vlR3075001 1 "1: 1  YES"  0 "0: 0  NO" 
label values R3075001 vlR3075001

label define vlR3401701 1 "1: 1  YES"  0 "0: 0  NO" 
label values R3401701 vlR3401701

label define vlR3657101 1 "1: 1  YES"  0 "0: 0  NO" 
label values R3657101 vlR3657101

label define vlR4007601 1 "1: 1  YES"  0 "0: 0  NO" 
label values R4007601 vlR4007601

label define vlR4418701 1 "1: 1  YES"  0 "0: 0  NO" 
label values R4418701 vlR4418701

label define vlR5081701 1 "1: 1  YES"  0 "0: 0  NO" 
label values R5081701 vlR5081701

label define vlR5167001 1 "1: 1  YES"  0 "0: 0  NO" 
label values R5167001 vlR5167001

label define vlR6479801 1 "1: 1  YES"  0 "0: 0  NO" 
label values R6479801 vlR6479801

label define vlR7007501 1 "1: 1  YES"  0 "0: 0  NO" 
label values R7007501 vlR7007501

label define vlR7704801 1 "1: 1  YES"  0 "0: 0  NO" 
label values R7704801 vlR7704801

label define vlR8497201 1 "1: 1  YES"  0 "0: 0  NO" 
label values R8497201 vlR8497201

label define vlT0989001 1 "1: 1  YES"  0 "0: 0  NO" 
label values T0989001 vlT0989001

label define vlT2210801 1 "1: 1  YES"  0 "0: 0  NO" 
label values T2210801 vlT2210801

label define vlT3108701 1 "1: 1  YES"  0 "0: 0  NO" 
label values T3108701 vlT3108701

label define vlT4113201 1 "1: 1  YES"  0 "0: 0  NO" 
label values T4113201 vlT4113201

label define vlT5023700 1 "1: 1  YES"  0 "0: 0  NO" 
label values T5023700 vlT5023700

label define vlT5771600 1 "1: 1  YES"  0 "0: 0  NO" 
label values T5771600 vlT5771600

  rename R0000100 CASEID_1979 
  rename R0173600 SAMPLE_ID_1979 
  rename R0214700 SAMPLE_RACE_78SCRN 
  rename R0214800 SAMPLE_SEX_1979 
  rename R0406511 DOI_EMPLOYED_1980 
  rename R0645680 DOI_EMPLOYED_1981 
  rename R0896711 DOI_EMPLOYED_1982 
  rename R1145111 DOI_EMPLOYED_1983 
  rename R1520311 DOI_EMPLOYED_1984 
  rename R1891011 DOI_EMPLOYED_1985 
  rename R2258111 DOI_EMPLOYED_1986 
  rename R2445511 DOI_EMPLOYED_1987 
  rename R2871301 DOI_EMPLOYED_1988 
  rename R3075001 DOI_EMPLOYED_1989 
  rename R3401701 DOI_EMPLOYED_1990 
  rename R3657101 DOI_EMPLOYED_1991 
  rename R4007601 DOI_EMPLOYED_1992 
  rename R4418701 DOI_EMPLOYED_1993 
  rename R5081701 DOI_EMPLOYED_1994 
  rename R5167001 DOI_EMPLOYED_1996 
  rename R6479801 DOI_EMPLOYED_1998 
  rename R7007501 DOI_EMPLOYED_2000 
  rename R7704801 DOI_EMPLOYED_2002 
  rename R8497201 DOI_EMPLOYED_2004 
  rename T0989001 DOI_EMPLOYED_2006 
  rename T2210801 DOI_EMPLOYED_2008 
  rename T3108701 DOI_EMPLOYED_2010 
  rename T4113201 DOI_EMPLOYED_2012 
  rename T5023700 DOI_EMPLOYED_2014 
  rename T5771600 DOI_EMPLOYED_2016 


//replace values less than 0 (i.e., refusal, don't know, invalid skip, valid skip, or non-interview) as "."

	foreach num of numlist 80/93 94(2)98 0(2)16 {
		
		if inrange(`num',80,98) local mil 19
		if inrange(`num',0,16) local mil 20
		
		local yy: display %02.0f `num' //if local num only has 1 digit, put a 0 in front of it
			
		tab DOI_EMPLOYED_`mil'`yy', m
		replace DOI_EMPLOYED_`mil'`yy' =. if DOI_EMPLOYED_`mil'`yy'<0
		tab DOI_EMPLOYED_`mil'`yy', m
		
		ren DOI_EMPLOYED_`mil'`yy' employed_`mil'`yy'
		label var employed_`mil'`yy' "R's employment status, `mil'`yy'"
		
	}
	
//drop unnecessary vars
	drop SAMPLE_ID_1979 SAMPLE_RACE_78SCRN SAMPLE_SEX_1979	
	
//save data
	sort CASEID_1979 // uniquely identifies Rs
	compress
	save ./rawdata/employment_status_byintdate.dta, replace

